home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mission 3
/
Mission 3.zip
/
Mission 3.iso
/
vollvers
/
adamaslg
/
ovl.src
/
panel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-12-18
|
7KB
|
302 lines
/*
Visual panel handler functions, including the redraw of the
object area and clicking the play/stop button.
*/
#include "extern.h"
#include <stddef.h>
#include <time.h>
#include <vdi.h>
int vdi_handle, colours, tx_width, tx_height;
#define min(a,b) ((a < b) ? a : b)
#define max(a,b) ((a > b) ? a : b)
/*
Open virtual workstation for panel redraw.
The panel handler creates it's own virtual
workstation to have it's own attributes for
filling and text output.
This function will be executed only once, after
loading the overlay.
*/
void open_panelvwk(void)
{
int work_in[10], work_out[57], extent[8], d;
int i;
int dummy, t_attr[10];
vdi_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
for(i = 0; i < 10; work_in[i++] = 1);
work_in[10] = 2;
v_opnvwk(work_in, &vdi_handle, work_out);
vqt_attributes(vdi_handle, t_attr);
vst_alignment(vdi_handle, 0, 5, &dummy, &dummy);
vst_height(vdi_handle, 6, &d, &d, &d, &d);
vqt_extent(vdi_handle, "W", extent);
tx_width = extent[2] - extent[0];
if (tx_width < 0) tx_width = -tx_width;
tx_height = extent[1] - extent[7];
if (tx_height < 0) tx_height = -tx_height;
vq_extnd(vdi_handle, FALSE, work_out);
colours = work_out[13];
}
/*
Close the special panel virtual
workstation.
This function will be executed only once, before
releasing the overlay from memory.
*/
void close_panelvwk(void)
{
v_clsvwk(vdi_handle);
}
/*
Calculate rectangle intersection
*/
int rc_intersect(int x1, int y1, int w1, int h1,
int x2, int y2, int w2, int h2,
int *xy)
{
int tx, ty, tw, th;
tw = min(x2 + w2, x1 + w1);
th = min(y2 + h2, y1 + h1);
tx = xy[0] = max(x2, x1);
ty = xy[1] = max(y2, y1);
xy[2] = tw - tx;
xy[3] = th - ty;
return ((tw > tx) && (th > ty));
}
/*
Draw one of the panel buttons.
x -> Button x - position
y -> Button y - position
w -> Button width
h -> Button height
button -> Button number, used to draw the correct symbol
pressed-> Is the button currently selected?
*/
void draw_button(int x, int y, int w, int h, int button, int pressed)
{
int xy[10];
int xc, yc;
if (colours >= 16)
vsf_color(vdi_handle, pressed ? 9 : 8);
else
vsf_color(vdi_handle, pressed ? 1 : 0);
xy[0] = x + 1;
xy[1] = y + 1;
xy[2] = x + w - 1;
xy[3] = y + h - 1 - 1;
vr_recfl(vdi_handle, xy); /* Button background */
xy[8] = xy[2] = xy[0] = x;
xy[9] = xy[7] = xy[1] = y + h - 1 - 1;
xy[5] = xy[3] = y + 1;
xy[6] = xy[4] = xy[0] + w - 1;
vsl_color(vdi_handle, 1);
v_pline(vdi_handle, 5, xy); /* Draw a surrounding border */
xy[0]++; xy[1]--;
xy[2]++; xy[3]++;
xy[4]--; xy[5]++;
xy[6]--; xy[7]--;
xy[8]++; xy[9]--;
if (pressed)
vsl_color(vdi_handle, 0);
v_pline(vdi_handle, 3, xy + 4); /* 3d style border black */
if (colours >= 16)
{
vsl_color(vdi_handle, pressed ? 1 : 0);
v_pline(vdi_handle, 3, xy); /* 3D style border white */
}
vsf_interior(vdi_handle, FIS_SOLID);
vsf_color(vdi_handle, pressed ? 0 : 1);
xc = x + w / 2;
yc = y + h / 2; /* Calculate button center */
switch(button)
{
case 0: /* Play button symbol */
{
xy[0] = xc - 3;
xy[1] = yc - 3;
xy[2] = xc + 3;
xy[3] = yc;
xy[4] = xc - 3;
xy[5] = yc + 3;
xy[6] = xy[0];
xy[7] = xy[1];
v_fillarea(vdi_handle, 4, xy);
break;
}
case 1: /* Stop button symbol */
{
xy[0] = xc - 3;
xy[1] = yc - 3;
xy[2] = xc + 3;
xy[3] = yc + 3;
vr_recfl(vdi_handle, xy);
break;
}
}
}
/*
Redraw object area
oinf -> Pointer to object info structure.
rx, ry -> Upper left corner of redraw area.
rw, rh -> Size of redraw area.
*/
void cdecl redraw_ovl(OBJ_INFO *oinf, int rx, int ry, int rw, int rh)
{
int wr_x, wr_y, wr_w, wr_h, obj_xy[4], o;
int clip_xy[4], xy[10];
vswr_mode(vdi_handle, MD_REPLACE);
if (rc_intersect(rx, ry, rw, rh,
oinf->scr_x, oinf->scr_y,
oinf->scr_w, oinf->scr_h,
obj_xy)) /* Redraw necessary ? */
{
wind_get(oinf->window_handle, WF_FIRSTXYWH, &wr_x, &wr_y, &wr_w, &wr_h);
while (wr_w && wr_h) /* Do it for each rectangle */
{
if (rc_intersect(obj_xy[0], obj_xy[1], obj_xy[2], obj_xy[3],
wr_x, wr_y, wr_w, wr_h, clip_xy)) /* Object in rectangle ? */
{
clip_xy[2] += clip_xy[0] - 1;
clip_xy[3] += clip_xy[1] - 1;
vs_clip(vdi_handle, 1, clip_xy); /* Set clipping */
vsf_interior(vdi_handle, FIS_SOLID);
if (colours >= 16)
vsf_color(vdi_handle, 8);
else
vsf_color(vdi_handle, 0);
vr_recfl(vdi_handle, clip_xy); /* Fill area */
vswr_mode(vdi_handle, MD_TRANS);
v_gtext(vdi_handle, oinf->obj_x + 2,
oinf->obj_y + (oinf->obj_h - tx_height) / 2,
((X32_INFO *)oinf->user)->name);
vswr_mode(vdi_handle, MD_REPLACE);
xy[8] = xy[2] = xy[0] = oinf->obj_x;
xy[9] = xy[7] = xy[1] = oinf->obj_y + oinf->obj_h - 1;
xy[5] = xy[3] = oinf->obj_y;
xy[6] = xy[4] = oinf->obj_x + oinf->obj_w - 1;
if (colours >= 16) /* Use 3D style */
{
vsl_color(vdi_handle, 1);
v_pline(vdi_handle, 3, xy);
vsl_color(vdi_handle, 0);
v_pline(vdi_handle, 3, xy + 4);
}
else /* Simple border */
{
vsl_color(vdi_handle, 1);
v_pline(vdi_handle, 5, xy);
}
for (o = 0; o < 2; o++)
{
draw_button(oinf->obj_x + oinf->obj_w - (o + 1) * (oinf->obj_h - 2) - 2,
oinf->obj_y,
oinf->obj_h, oinf->obj_h,
o,
((X32_INFO *)oinf->user)->button_pressed == o);
}
vs_clip(vdi_handle, 0, clip_xy); /* Clipping off */
}
wind_get(oinf->window_handle, WF_NEXTXYWH, &wr_x, &wr_y, &wr_w, &wr_h);
}
}
}
/*
This function will be called on left mouse click in object area.
It checks, if one of the two buttons play/stop is selected.
If so, it sets the button state to selected, does the corresponding
action, wait for releasing the mouse button, deselect the button
and returns.
*/
void cdecl onclick_ovl(OBJ_INFO *oinf, int clicks, int mx, int my)
{
int bx, by;
int o, m_button, d;
for (o = 0; o < 2; o++)
{
bx = oinf->obj_x + oinf->obj_w - (o + 1) * (oinf->obj_h - 2) - 2;
by = oinf->obj_y;
if (mx >= bx && mx < bx + oinf->obj_h &&
my >= by && my < by + oinf->obj_h) /* Is it the button ? */
{
graf_mouse(M_OFF, 0L);
((X32_INFO *)oinf->user)->button_pressed = o; /* Select button */
redraw_ovl(oinf, bx, by, oinf->obj_h, oinf->obj_h);
switch(o)
{
case 0:
start_sound(oinf);
break;
case 1:
stop_sound(oinf);
break;
}
/* Wait for mouse release */
do
{
evnt_multi(MU_TIMER, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
NULL, 30, 0,
&d, &d, &m_button,
&d, &d, &d);
}while(m_button & 1);
/* Deselect button */
((X32_INFO *)oinf->user)->button_pressed = -1;
redraw_ovl(oinf, bx, by, oinf->obj_h - 2, oinf->obj_h);
graf_mouse(M_ON, 0L);
break;
}
}
}